// pages/order/pre-status/pre-status.js

//pages/order/pre-status/pre-status?orderResult='xx'
var util = require('../../../utils/util.js')
var app = getApp()
var that

Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderResult: null, //订单结果数据

    statusImg: null,

    isShowContactNo: false, //是否显示联系客服
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this
    try {
      var orderResult = JSON.parse(decodeURIComponent(options.orderResult))
      var statusImg = "/resources/image/order_status_fail.png"
      var isShowContactNo = false
      console.log(options, orderResult)
      if (orderResult.orderStatus == 'success') {
        statusImg = "/resources/image/order_status_success.png"
      } else if (orderResult.orderStatus == 'fail') {
        statusImg = "/resources/image/order_status_fail.png"
        isShowContactNo = true
      } else if (orderResult.orderStatus == 'overflow') {
        statusImg = "/resources/image/order_status_overflow.png"
        isShowContactNo = true
      } else{
        statusImg = "/resources/image/order_status_going.png"
      }
      if (orderResult.orderStatus == 'success' || orderResult.orderStatus == 'noSend' || orderResult.orderStatus == 'noTake'){
        that.orderSaveMoneyInfo(orderResult.orderId);
      }

      if (isShowContactNo && orderResult.hotlineNo) {
        isShowContactNo = true
      } else {
        isShowContactNo = false
      }

      this.setData({
        orderResult: orderResult,
        statusImg: statusImg,
        isShowContactNo: isShowContactNo
      })
    } catch (e) {
      console.log(e)
    }
  },
  onShareAppMessage: function (res) {
    return util.handleShareApp()
  },
  /**
   * 联系客服点击
   */
  onContactClick() {
    var phoneNo = this.data.orderResult.hotlineNo
    if (phoneNo) {
      wx.makePhoneCall({
        phoneNumber: phoneNo,
      })
    }
  },

  /**
   * 查询省钱信息
   */
  orderSaveMoneyInfo(orderId){
    app.orderSaveMoneyInfo(orderId, function (e) {
      that.setData({
        orderSaveMoneyInfo: e.text
      })
    })
  }
  
})
